﻿Public Class FormNgOper
    Private WithEvents UcDigitalKeyboard1 As ucDigitalKeyboard
    Public usr As String
    Public source As String
    Public ty As String
    Public b_gt_sys_id As String
    Public current_procedure_No As Integer
    Public oper_num_all As String
    Public ng_num_all As String
    Dim objReasonMst As New clsReasonMst
    Dim objGtNgReasonDetails As New clsGtNgReasonDetails
    Private Sub FormNgOper_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        lbl_gt_sys_id.Text = b_gt_sys_id
        setData()
        If ty.Equals("0") Then
            objReasonMst.setMstChkList(chkNg_Reason, "gjb", current_procedure_No.ToString())
        Else
            objReasonMst.setMstChkList(chkNg_Reason, "flb", current_procedure_No.ToString())
        End If
    End Sub

    Private Sub setData()
        SpinEdit5.Value = Decimal.Parse(oper_num_all)
        SpinEdit6.Value = Decimal.Parse(ng_num_all)
        txt_operable_num.Value = SpinEdit5.Value - SpinEdit6.Value
    End Sub

    Private Sub btnSave_Click(sender As Object, e As EventArgs) Handles btnSave.Click
        If txt_num.Value > 0 Then
            If txt_num.Value <= txt_operable_num.Value Then
                Dim chklstChecked As Boolean = False
                For i As Integer = 0 To chkNg_Reason.Items.Count - 1
                    If chkNg_Reason.Items(i).CheckState = CheckState.Checked Then
                        chklstChecked = True
                    End If
                Next
                If chklstChecked = False Then
                    MsgBox("请选择不合格原因！")
                    chkNg_Reason.Select()
                    Exit Sub
                End If
                Dim ng_reason As String = String.Empty
                For i As Integer = 0 To chkNg_Reason.Items.Count - 1
                    If chkNg_Reason.Items(i).CheckState = CheckState.Checked Then
                        ng_reason &= chkNg_Reason.Items(i).Value & "/"
                    End If
                Next
                ng_reason = ng_reason.Substring(0, ng_reason.Length - 1)
                Dim en As New entity_gt_ng_reason_details
                en.procedure_No = current_procedure_No.ToString()
                en.ng_num = Integer.Parse(txt_num.Value)
                en.ng_reason = ng_reason
                en.validity = "1"
                en.oper = usr
                en.b_gt_sys_id = Integer.Parse(lbl_gt_sys_id.Text)
                Dim rtn As Integer = objGtNgReasonDetails.save(en)
                If rtn <> -2 Then
                    If source.Equals("jp") Then
                        CType(Owner, FormOperJP).SetDgvResultData1()
                        CType(Owner, FormOperJP).setDgvNgOperData()
                    End If
                    If source.Equals("psqx1") Then
                        CType(Owner, FormOperPSQX1).SetDgvResultData1()
                        CType(Owner, FormOperPSQX1).setDgvNgOperData()
                    End If
                    If source.Equals("psqx0") Then
                        CType(Owner, FormOperPSQX0).SetDgvResultData()
                        CType(Owner, FormOperPSQX0).setDgvNgOperData()
                    End If
                    If source.Equals("psqx00") Then
                        CType(Owner, FormOperPSQX00).SetDgvResultData1()
                        CType(Owner, FormOperPSQX00).setDgvNgOperData()
                    End If
                    If source.Equals("6gw") Then
                        CType(Owner, Form6GongWeiOut).SetDgvResultData()
                        CType(Owner, Form6GongWeiOut).setDgvNgOperData()
                    End If
                    If source.Equals("check") Then
                        CType(Owner, FormCheck).SetDgvResultData1()
                        CType(Owner, FormCheck).setDgvNgOperData()
                    End If
                    MsgBox("保存成功")
                    For i As Integer = 0 To chkNg_Reason.Items.Count - 1
                        chkNg_Reason.Items(i).CheckState = CheckState.Unchecked
                    Next
                    Close()
                Else
                    MsgBox("保存失败")
                End If
            Else
                MsgBox("不合格数量>可操作数量")
            End If
        Else
            MsgBox("不合格数量需>0")
        End If
    End Sub

    Private Sub txt_num_MouseDown(sender As Object, e As MouseEventArgs) Handles txt_num.MouseDown
        UcDigitalKeyboard1 = New ucDigitalKeyboard
        If sender.MaskBox.Mask.EditMask = "d" Then
            UcDigitalKeyboard1.B_01 = False
        Else
            UcDigitalKeyboard1.B_01 = True
        End If

        If sender.GetType().Name.Equals("TextEdit") Then
            UcDigitalKeyboard1.B_02 = True
        Else
            UcDigitalKeyboard1.B_02 = False
        End If

        UcDigitalKeyboard1.Txt = sender

        Me.Controls.Add(UcDigitalKeyboard1)
        UcDigitalKeyboard1.Show()
        UcDigitalKeyboard1.BringToFront()
        UcDigitalKeyboard1.Focus()
    End Sub

End Class